package com.label.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.label.Dao.PersonsAppMapper;
import com.label.Model.Do.PersonsApp;
import com.label.Service.PersonsAppService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PersonsAppServiceImpl extends ServiceImpl<PersonsAppMapper, PersonsApp> implements PersonsAppService {

    @Resource
    private PersonsAppMapper personsAppMapper;

    @Override
    public PersonsApp addApp(PersonsApp personsApp) {
        if(personsAppMapper.insert(personsApp) != 0)
            return personsApp;
        return null;
    }

    @Override
    public Boolean delAppById(PersonsApp personsApp) {
        return personsAppMapper.deleteById(personsApp.getId()) != 0;
    }

    @Override
    public List<PersonsApp> getAllApp() {
        return personsAppMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public List<PersonsApp> getApp(PersonsApp personsApp) {
        return personsAppMapper.selectList(new QueryWrapper<PersonsApp>().lambda().eq(PersonsApp::getCreator,personsApp.getCreator()));
    }

    @Override
    public PersonsApp updateApp(PersonsApp personsApp) {
        if(personsAppMapper.updateById(personsApp) != 0)
            return personsApp;
        return null;
    }

    @Override
    public PersonsApp getOneById(PersonsApp personsApp) {
        return personsAppMapper.selectById(personsApp.getId());
    }
}
